package com.wx.wxapp.service;


import com.wx.wxapp.dao.UserMapper;
import com.wx.wxapp.entity.User;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserSerivce {
    @Autowired
    private SqlSessionFactory sqlSessionFactory;

    public void insertUser(String nickname,String address,String openid,String image){

        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);

        if(null != userMapper.selectByOpenid(openid)){
            System.out.println("用户已存在");
        }
        else {
            User user = new User();
            user.setNickname(nickname);
            user.setOpenid(openid);
            user.setAddress(address);
            user.setImage(image);
            userMapper.insert(user);
            sqlSession.close();
        }
    }
}
